<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">


<meta name="google-site-verification" content="E9deYnivN5MuHMuIfiMZZfS0alv-d_0UjcwjBL79lGU" />



<meta name="baidu-site-verification" content="iHYWJxscwD" />










<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />



  <meta name="google-site-verification" content="true" />








  <meta name="baidu-site-verification" content="true" />







  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="学习笔记,量化投资,kaggle竞赛,机器学习," />










<meta name="description" content="以下竞赛介绍翻译自官网“低买高卖”，听起来很容易……实际上，为盈利而交易是一个很难的问题，尤其是在当今这个快速变化的复杂金融市场上。电子化交易允许在几分之一秒内进行数千次交易，导致有几乎无限的获利的机会。在一个完美有效市场，买卖者拥有做出理性交易决策所需要的所有信息。结果，产品会总是保持在它们的“公平价格”(fair values)，并且从来不会被低估或高估。然而现实的金融市场不是完美有效的。开发">
<meta property="og:type" content="article">
<meta property="og:title" content="量化投资学习笔记92——Kaggle量化交易竞赛JaneStreetMarketPrediction笔记1">
<meta property="og:url" content="https://zwdnet.github.io/2020/12/14/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B092%E2%80%94%E2%80%94Kaggle%E9%87%8F%E5%8C%96%E4%BA%A4%E6%98%93%E7%AB%9E%E8%B5%9BJaneStreetMarketPrediction%E7%AC%94%E8%AE%B01/index.html">
<meta property="og:site_name" content="赵瑜敏的口腔医学专业学习博客">
<meta property="og:description" content="以下竞赛介绍翻译自官网“低买高卖”，听起来很容易……实际上，为盈利而交易是一个很难的问题，尤其是在当今这个快速变化的复杂金融市场上。电子化交易允许在几分之一秒内进行数千次交易，导致有几乎无限的获利的机会。在一个完美有效市场，买卖者拥有做出理性交易决策所需要的所有信息。结果，产品会总是保持在它们的“公平价格”(fair values)，并且从来不会被低估或高估。然而现实的金融市场不是完美有效的。开发">
<meta property="og:locale">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/01.png">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/02.png">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/03.png">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/04.png">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/05.png">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/06.png">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/07.png">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/08.png">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/09.png">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/10.png">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/wx.jpg">
<meta property="article:published_time" content="2020-12-14T08:25:18.000Z">
<meta property="article:modified_time" content="2021-01-08T09:28:31.000Z">
<meta property="article:author" content="赵瑜敏">
<meta property="article:tag" content="学习笔记">
<meta property="article:tag" content="量化投资">
<meta property="article:tag" content="kaggle竞赛">
<meta property="article:tag" content="机器学习">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/01.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://zwdnet.github.io/2020/12/14/量化投资学习笔记92——Kaggle量化交易竞赛JaneStreetMarketPrediction笔记1/"/>





  <title>量化投资学习笔记92——Kaggle量化交易竞赛JaneStreetMarketPrediction笔记1 | 赵瑜敏的口腔医学专业学习博客</title>
  








<meta name="generator" content="Hexo 5.4.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">赵瑜敏的口腔医学专业学习博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://zwdnet.github.io/2020/12/14/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B092%E2%80%94%E2%80%94Kaggle%E9%87%8F%E5%8C%96%E4%BA%A4%E6%98%93%E7%AB%9E%E8%B5%9BJaneStreetMarketPrediction%E7%AC%94%E8%AE%B01/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/tx.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="赵瑜敏的口腔医学专业学习博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">量化投资学习笔记92——Kaggle量化交易竞赛JaneStreetMarketPrediction笔记1</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-12-14T08:25:18+00:00">
                2020-12-14
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84/" itemprop="url" rel="index">
                    <span itemprop="name">量化投资</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2.1k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  7
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>以下竞赛介绍翻译自<a target="_blank" rel="noopener" href="https://www.kaggle.com/c/jane-street-market-prediction">官网</a><br>“低买高卖”，听起来很容易……<br>实际上，为盈利而交易是一个很难的问题，尤其是在当今这个快速变化的复杂金融市场上。电子化交易允许在几分之一秒内进行数千次交易，导致有几乎无限的获利的机会。<br>在一个完美有效市场，买卖者拥有做出理性交易决策所需要的所有信息。结果，产品会总是保持在它们的“公平价格”(fair values)，并且从来不会被低估或高估。然而现实的金融市场不是完美有效的。<br>开发出交易策略来识别和利用市场无效性是一个挑战。即便一个策略在目前是能获利的，它在未来未必能获利，而且市场波动会使得预测任何给定的交易的盈利情况变得不可能。结果，很那区分好运气和做出了好的交易决策。<br>在本竞赛的头三个月，你将构建你自己的量化交易模型以最大化你的收益，你所使用的市场数据来自全球主要证券交易市场的数据。接下来，你将用未来市场的回报测试模型，并在排行榜上收到反馈。<br>您的挑战包括使用历史数据，数学工具，技术工具，以创建一个模型，尽可能符合于现实。你将被给予一定数量的潜在交易机会，你的模型必须选择接受或拒绝。<br>一般来说，如果一个模型能够产生较高的预测度，以选择正确的交易来执行，它们将会在传递市场信号，推动价格接近“公平”价格中发挥很重要的作用。即，一个更好的模型意味着市场会更有效。然而，开发一个好的模型意味着很多挑战，包括很低的信噪比，潜在的冗余，强的特征相关性，以及难以求解的数学问题。<br>Jane Street是一个量化交易机构，开发了很多交易模型并获利。这个问题是对他们日常工作的简化。<br>结果评估：采用效用分数。测试集的每一行代表一个交易机会，你必须预测一个行动值（action value），值为1进行交易，值为0拒绝交易。每个交易j有两个值，weight和resp，代表一个收益结果。<br>对于每个日期(date)i，定义<br><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/01.png"><br>其中i的绝对值是测试集中的不同的数据的个数。效用分数定义为：<br><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/02.png"><br>提交文件：必须用python time-series API提交数据，它能确保模型没有使用未来数据。使用方法如下：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> janestreet</span><br><span class="line">env = janestreet.make_env() <span class="comment"># initialize the environment</span></span><br><span class="line">iter_test = env.iter_test() <span class="comment"># an iterator which loops over the test set</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> (test_df, sample_prediction_df) <span class="keyword">in</span> iter_test:</span><br><span class="line">    sample_prediction_df.action = <span class="number">0</span> <span class="comment">#make your 0/1 prediction here</span></span><br><span class="line">    env.predict(sample_prediction_df)</span><br></pre></td></tr></table></figure>
<p>时间限制：<br>参加时间限制：2021年2月15日之前。<br>组队合并限制：2021年2月15日之前。<br>最后提交限制：2021年2月22日之前。<br>预测时间显示：2021年8月23日之前。<br>不允许在团队外私自分享代码或数据。<br>奖金：<br>总奖金10万刀，一等奖4万刀，二等奖2万刀，三等奖1万刀，四至九名，5000刀。</p>
<p>数据描述<br>包括一系列匿名的特征，feature_0…feature_129,代表了真实市场数据。数据集中每一行代表了一个交易机会，你的模型要根据这些数据预测一个行动值：1（交易）或0（不交易）。每个交易有一个相应的weight和resp，它们一起代表了一个交易的回报。date列是一个整数，代表了交易的日期，ts_id代表了一个时间顺序。为了匿名化(anonymized)特征值，提供了一个特征值的元数据。<br>在训练集，train.csv，提供了一个resp值，还有其它四个resp_1,…resp_4值，代表不同时区的收益值。在测试集中没有这些数据。weight=0的数据是为了完整性保留在数据集中，尽管它们对模型评分没有贡献。<br>使用时间序列API(time-series API)来确保模型没有使用未来数据。当提交数据的时候，需要使用时间序列API。</p>
<p>实操记录<br>首先在服务器上下载数据，有2.5G，直接读取，超过内存报错啦。<br>想了很多办法，先读取数据的1/100，画图，意外发现数据有两种类型，一种像随机数据<br><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/03.png"><br>还有一种是类似三角形的<br><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/04.png"><br>之后，发现一个处理数据规模大于物理内存的库:dask，用法跟pandas类似，只是它是延迟计算的，真正算的时候调用computer成员函数:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> dask.dataframe <span class="keyword">as</span> dd</span><br><span class="line">data = dd.read_csv(<span class="string">&quot;./train.csv&quot;</span>)</span><br><span class="line">fig = plt.figure()</span><br><span class="line">plt.plot(data[<span class="string">&quot;weight&quot;</span>].values.compute())</span><br><span class="line">plt.savefig(<span class="string">&quot;./output/weight.png&quot;</span>)</span><br></pre></td></tr></table></figure>
<p>dask官网:<a target="_blank" rel="noopener" href="https://docs.dask.org/">https://docs.dask.org</a><br>这样把训练集所有数据按列分别画图，等于用时间换空间，在服务器上整整运行了一天多才完。把图片down下来看看，完整的数据的图形就比较正常了。但是实际预测的时候用dask可能太慢了，还是就用1/10的数据吧。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">n = <span class="number">2390491</span></span><br><span class="line">row_read = <span class="built_in">int</span>(n/<span class="number">10</span>)</span><br><span class="line">data = pd.read_csv(<span class="string">&quot;./train.csv&quot;</span>, nrows = row_read)</span><br><span class="line">print(data.info())</span><br><span class="line">data.to_csv(<span class="string">&quot;./small_train.csv&quot;</span>)</span><br></pre></td></tr></table></figure>
<p>之后就用small_train.csv里的数据干活吧。<br>把small_train.csv从服务器上下载回来，1/10的数据就有591MB。<br>很多特征里有空行。<br><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/05.png"><br>特征之间差异很大，还要进行归一化吧。<br><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/06.png"><br>先填充空值</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 复制数据，进行操作</span></span><br><span class="line">newdata = data.copy()</span><br><span class="line"><span class="comment"># 填充空值 向前填充</span></span><br><span class="line">newdata = newdata.fillna(method = <span class="string">&quot;backfill&quot;</span>)</span><br><span class="line">print(newdata.info(verbose = <span class="literal">True</span>, null_counts = <span class="literal">True</span>))</span><br></pre></td></tr></table></figure>
<p><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/07.png"><br>然后归一化，用max-min归一化。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 数据归一化</span></span><br><span class="line">features = (features - features.<span class="built_in">min</span>())/(features.<span class="built_in">max</span>() - features.<span class="built_in">min</span>())</span><br><span class="line">print(features.describe())</span><br><span class="line"><span class="comment"># 更新原来的特征数据</span></span><br><span class="line">newdata.update(features)</span><br><span class="line">print(newdata.head())</span><br></pre></td></tr></table></figure>
<p>现在可以开始干活了。先用weight和resp构造一个训练集的行动变量。参考<a target="_blank" rel="noopener" href="https://github.com/amareshgood/Jane-Street-Market-Prediction/blob/main/jane_street_market_predictions.ipynb">这里</a></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 够造训练集的行动变量</span></span><br><span class="line">newdata[<span class="string">&quot;action&quot;</span>] = ((newdata[<span class="string">&quot;weight&quot;</span>].values * newdata[<span class="string">&quot;resp&quot;</span>].values) &gt; <span class="number">0</span>).astype(<span class="string">&quot;int&quot;</span>)</span><br></pre></td></tr></table></figure>
<p>把上述代码放到一个函数里，算是特征工程了。<br>接下来可以开始训练了。先用最简单的多元线性回归吧。<br>参考<a target="_blank" rel="noopener" href="https://github.com/767472021/Jane-Street-Market-Prediction/blob/master/EDA.ipynb">这里</a></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 线性回归模型</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">LR</span>(<span class="params">data</span>):</span></span><br><span class="line">    train_set, test_set, train_action, test_action = train_test_split(data.loc[:, <span class="string">&quot;feature_0&quot;</span>:<span class="string">&quot;feature_129&quot;</span>], data.action, test_size = <span class="number">0.2</span>)</span><br><span class="line">    print(<span class="built_in">len</span>(train_set))</span><br><span class="line">    <span class="comment"># 训练</span></span><br><span class="line">    linreg = LinearRegression()</span><br><span class="line">    linreg.fit(train_set, train_action)</span><br><span class="line">    <span class="comment"># 预测</span></span><br><span class="line">    train_pred = linreg.predict(train_set)</span><br><span class="line">    test_pred = linreg.predict(test_set)</span><br><span class="line">    <span class="comment"># 模型评估</span></span><br><span class="line">    print(<span class="string">&quot;train MSE:&quot;</span>, metrics.mean_squared_error(train_action, train_pred))</span><br><span class="line">    print(<span class="string">&quot;test MSE:&quot;</span>, metrics.mean_squared_error(test_action, test_pred))</span><br><span class="line">    print(<span class="string">&quot;train RMSE:&quot;</span>, np.sqrt(metrics.mean_squared_error(train_action, train_pred)))</span><br><span class="line">    print(<span class="string">&quot;test RMSE:&quot;</span>, np.sqrt(metrics.mean_squared_error(test_action, test_pred)))</span><br><span class="line">    <span class="comment"># 保存模型到文件</span></span><br><span class="line">    <span class="comment"># joblib.dump(linreg, &quot;LinesRegress.pkl&quot;)</span></span><br><span class="line">    <span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&quot;LinesRegress.pkl&quot;</span>, <span class="string">&quot;wb&quot;</span>) <span class="keyword">as</span> fw:</span><br><span class="line">        pickle.dump(linreg, fw)</span><br><span class="line">    print(test_pred)</span><br></pre></td></tr></table></figure>
<p>提交的时候才发现，预测结果是浮点数，提交要求的是整数。就简单设置成大于0的结果设为1，小于等于0的结果设为0。<br>第一次用notebook的方式提交，参考了<a target="_blank" rel="noopener" href="https://www.kaggle.com/gogo827jz/jane-street-neural-network-starter">这里</a><br>写了提交的notebook，折腾半天，终于提交成功了。<br>结果:<br><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/08.png"><br>比全是1或者随机的结果好，但是分很低。排行榜上分最高的大神分数有8000多分……再努力吧。另外处理缺失值的方法得改了，提交的时候测试数据貌似是用一个for循环一个值一个值的给出的，而不是一下子给出来。<br>照<a target="_blank" rel="noopener" href="https://www.kaggle.com/harshit2708/linear-regression">人家的notebook</a>改一个看看<br>看了人家的，是预测resp变量，然后再用weight×resp的值决定行动值是0还是1。另外是用sklearn的SimpleImputer, MissingIndicator来处理缺失值。<br>画了一下预测值和实际值。<br><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/09.png"><br>再提交看看。<br><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/blog0178-QTLearn/65/10.png"><br>尝试了几次，都是0分。不知道哪里出问题了。不管怎么样，框架是有了。细节再慢慢搞吧。<br><a target="_blank" rel="noopener" href="https://github.com/zwdnet/JSMPwork">代码</a></p>
<p>我发文章的三个地方，欢迎大家在朋友圈等地方分享，欢迎点“在看”。<br>我的个人博客地址：<a href="https://zwdnet.github.io/">https://zwdnet.github.io</a><br>我的知乎文章地址： <a target="_blank" rel="noopener" href="https://www.zhihu.com/people/zhao-you-min/posts">https://www.zhihu.com/people/zhao-you-min/posts</a><br>我的微信个人订阅号：赵瑜敏的口腔医学学习园地</p>
<p><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/wx.jpg"></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>欢迎打赏！感谢支持！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/mm_facetoface_collect_qrcode_1542944836634.png" alt=" 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/1542944857770.jpg" alt=" 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" rel="tag"># 学习笔记</a>
          
            <a href="/tags/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84/" rel="tag"># 量化投资</a>
          
            <a href="/tags/kaggle%E7%AB%9E%E8%B5%9B/" rel="tag"># kaggle竞赛</a>
          
            <a href="/tags/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/" rel="tag"># 机器学习</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/12/04/%E7%AC%AC%E4%BA%8C%E5%B1%8A%E4%B8%AD%E6%AC%A7%E5%A4%9A%E5%AD%A6%E7%A7%91%E5%92%AC%E5%90%88%E8%AE%BA%E5%9D%9B%E5%90%AC%E8%AF%BE%E8%AE%B0%E5%BD%95/" rel="next" title="第二届中欧多学科咬合论坛听课记录">
                <i class="fa fa-chevron-left"></i> 第二届中欧多学科咬合论坛听课记录
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/12/18/CAED%E5%A4%A7%E5%92%96%E7%97%85%E4%BE%8B%E5%88%86%E4%BA%AB/" rel="prev" title="CAED大咖病例分享">
                CAED大咖病例分享 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC80MTA2Mi8xNzU4Nw=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/tx.jpg"
                alt="" />
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%20%7C%7C%20archive">
              
                  <span class="site-state-item-count">452</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">29</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">544</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">本站版权归赵瑜敏所有，如欲转载请与本人联系。</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">1225.8k</span>
  
</div>









<div>
  <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1275447216'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s11.cnzz.com/z_stat.php%3Fid%3D1275447216%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));</script>
</div>

        







  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1275447216&web_id=1275447216" language="JavaScript"></script>
  </div>



        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  





  

  

  

  
  

  

  

  

  
</body>
</html>
